import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from "vuex-persistedstate"
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    hostLists: [],//猜你喜欢
    history: [],//搜素历史
    focusData: [],//我的关注
  },
  getters: {
  },
  mutations: {
    setHostList(store, paylod) {
      store.hostLists = paylod;
      console.log(store.hostLists);
    },
    PushHistory(store, paylod) {
      if (store.history.indexOf(paylod) == -1) {
        store.history.push(paylod);
      }
    },
    DelHistory(store) {
      store.history = [];
    },
    Shopfocus(store, paylod) {
      store.focusData.push(paylod)
    },
    CancelData(store, paylod) {
      var arr = store.focusData.filter((item, index) => {
        return item.proid !== paylod.proid
      })
      store.focusData = arr;
      console.log(store.focusData);
    }
  },
  actions: {

  },
  modules: {

  },
  plugins: [
    createPersistedState({
      // 存储方式：localStorage、sessionStorage、cookies
      storage: window.sessionStorage,
      // 存储的 key 的key值
      key: "store",
      render(state) {
        // 要存储的数据：本项目采用es6扩展运算符的方式存储了state中所有的数据
        return { ...state };
      }
    })
  ]
})
